﻿ 
<%@page import="com.hh.bss.util.StringHelper" %>
<%
  String custId=request.getParameter("custId");    
  if (StringHelper.isEmpty(custId)) custId="0";
  
%>  
<script>

  var custId=<%=custId%>;
</script> 	
<!DOCTYPE html>  
<html>  
<head>  
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
    <meta name="keywords" content="客户联系人">  
    <meta name="description" content="客户联系人">  
    <title>客户联系人管理</title>  
    
    <%@ include file="/WEB-INF/inc/default.jsp"%>
    <jsp:include page="/WEB-INF/inc/dic.jsp"/>

</head>  
<body>  
    
      
    <table id="dg" title="客户联系人管理" style="width:1100px;height:500px"  
            url="/customer/customerContacter/list.do"  
            toolbar="#toolbar" pagination="true"  
            rownumbers="true" fitColumns="true" loadMsg="正在查询,请稍候..." singleSelect="false">  

    </table>  
    <div id="toolbar">  
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="add()">新增</a>  
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="edit()">修改</a>  
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="deletes()">删除</a>  
        
    </div>  
    <!-- edit form窗体（开始） -->  
    <div id="dlg" style="display:none;">  
        <!--    
        <form id="fm" method="post" novalidate>  
        	  	  	 <input type="hidden" name="id" > 
        	  	  	 <input type="hidden" name="custId" > 
	        		     <input type="hidden" name="cvId" > 	        		     
	        		     <div class="fitem">  
                     <label style="width:100px">姓名<font color="red">*</font>:</label>                       
                     <input name="cvName" disabled="true" class="easyui-box easyui-validatebox"  required="true">    
                     <a href="#" class="easyui-linkbutton" id="contacterselectcv" >选择</a>                   
                   </div>
	        		     <div class="fitem">  
                     <label style="width:100px">联系人角色<font color="red">*</font>:</label>                                            
                     
                     <input class="easyui-combobox"  required="true" name="role" style="width:100px;"  data-options="data:__getConstantCategory('CUSTOMER_CONTACTER'),valueField:'code', textField:'value', multiple:false,panelHeight:'auto',mode:'remote' ">  
                   </div> 
	        		     	        		     
	        		     
	        		     	        		     
        </form>  
        <div  style="text-align:center">  
          <a href="javascript:void(0)" id="btn-save" class="easyui-linkbutton" iconCls="icon-ok" ">Save</a>  
          <a href="javascript:void(0)" id="btn-close" class="easyui-linkbutton" iconCls="icon-cancel">关闭</a>  
        </div>
        -->
    </div>  
    <!-- edit form窗体（结束） -->  
    <!-- query form窗体(开始) -->  
    <div id="dlg_query" style="display:none;">  
    	  <!--
        <div class="ftitle">客户联系人</div>  
        <form id="fm_query" method="post" novalidate>  
            
                     		     
	        		     <div class="fitem">  
                     <label style="width:100px">联系人角色:</label>                                            
                     <input class="easyui-combobox"  required="true" name="role" style="width:50px;"  data-options="data:__getConstantCategory('CUSTOMER_CONTACTER'),valueField:'code', textField:'value', multiple:false,panelHeight:'auto',mode:'remote' ">                      
                   </div> 
	        		     <div class="fitem">  
                     <label style="width:100px">对应的人才:</label>                       
                     <input name="cvName" class="easyui-numberbox">                       
                   </div>	        		     
	        		    
              
        </form>
        <div  style="text-align:center">  
          <a href="javascript:void(0)" id="btn-query" class="easyui-linkbutton" iconCls="icon-ok" ">查询</a>  
          <a href="javascript:void(0)" id="btn-query-close" class="easyui-linkbutton" iconCls="icon-cancel">关闭</a>  
        </div>  
        -->
    </div> 
    <!-- query form窗体(结束) -->  
    
    <script type="text/javascript">  
        var url;  
        
        var url;  
        var optWin = $.window({
		       		 title:"新增客户联系人",
		       		 tplRef:"dlg",//这个属性指定模板id
		       		 height:200,
		       		 width:500,		       		 
		       		 closed:true,		       		 
		       		 onComplete:function(){
		       		 	  //窗口里面的初始化,最好是在这个事件里面进行
		       		 	  var curWin=this;
		       		 	  var doForm=curWin.find('#fm');
		       		 	  curWin.doForm=doForm;
		       		 	  this.find("#btn-close").click(function(){		       		 	  	
		       		 	  	   curWin.window('close');
		       		 	  });
		       		 	  
		       		 	  
		       		 	  this.find('#contacterselectcv').click(function(){		       		 	  			       		 	  	   
		       		 	  	   
		       		 	  	   curWin.openWin.selectCv();
		       		 	  });
		       		 	  this.find("#btn-save").click(function(){		       		 	  	
		                 		  if (!doForm.form('validate')) return;
		                 		  
		                 		  doForm.form('submit',{  
                            url: curWin.url,  
                            onSubmit: function(){                              	  
                                return doForm.form('validate');  
                            },  
                            success: function(result){  
                                var result = eval('('+result+')');                      
                                if (result.success == true){  
                                    //$.messager.alert('信息',result.msg,'info');  
                                    alert(result.msg);
                                    curWin.window('close');
                                    curWin.openWin.reload();
                                    
                                } else {  
                                    //$.messager.alert('错误',result.msg,'error');
                                    alert(result.msg);
                                }  
                            }  
                       }); 		 
		              });
		       		   
		       		 }
		    });
		    
		    var queryWin = $.window({
		       		 title:"客户联系人查询",
		       		 tplRef:"dlg_query",//这个属性指定模板id
		       		 height:200,		       		 
		       		 closed:true,		       		 
		       		 onComplete:function(){
		       		 	  //窗口里面的初始化,最好是在这个事件里面进行
		       		 	  var curWin=this;
		       		 	  var doForm=curWin.find('#fm_query');
		       		 	  curWin.doForm=doForm;
		       		 	  this.find("#btn-query-close").click(function(){		       		 	  	
		       		 	  	   curWin.window('close');
		       		 	  });
		       		 	  this.find("#btn-query").click(function(){
		       		 	  			                 		  
		                 		 //var formdata=$('#fm_query').formToArray(); 
		                 		 curWin.window('close');
		                 		 var formdata=curWin.find('#fm_query').formToArray();   		 
		                 		 curWin.openWin.query(formdata);
		              });
		       		   
		       		 }
		    });
        
        
        function add(){         	                        
            optWin.window('open'); 
            optWin.openWin=window;    
            optWin.url='/customer/customerContacter/save.do';  
            optWin.doForm.form('clear');
            optWin.doForm.find('input[name="custId"]').attr("value",custId);
            optWin.window('setTitle','新增客户联系人');
        }  
        function doEdit(id){  
        	optWin.window('open');
		             optWin.doForm.form('clear');
		             optWin.url='/customer/customerContacter/update.do'; 
		             optWin.doForm.form('load','/customer/customerContacter/get.do?id='+id);   
		             optWin.window('setTitle','修改客户联系人');
		             optWin.openWin=window;
        }	
        function edit(){  
            //var row = $('#dg').datagrid('getSelected');  
            var rows = $('#dg').datagrid('getSelections');
            if (!rows||rows.length==0){
            	 $.messager.alert('提示','请选择要修改的行','info');
            	 return;
            }
            if (!rows||rows.length>1){
            	 $.messager.alert('提示','不能选择多行','info');
            	 return;
            }
            if (rows){  
                 
		             doEdit(rows[0].id);
            }  
        }  
        var selectCvWin;
         function selectCv(){
        	if (selectCvWin)
                 selectCvWin.window('open');
             else selectCvWin = $.window({
		      	   	title:"选择人选",
		      	   	url:"/talent/cv/selectCvPage.do",
		      	   	isIframe:true,
		      	   	height:380,
		      	   	modal:false,		      	   	
		      	   	width:1000,
		      	   	onComplete:function(jq,iframe){	
		      	   		         	   		   	      	   		
		      	   		   var fwindow = $.window.util.getFrameWindow(iframe);		      	   		
		      	   		   var ijq = fwindow.jQuery;		
		      	   		   var curWin=this;   
		      	   		   
		      	   		   var curWin=this;
					
					           fwindow.closeWin=function(){
					           	   curWin.window('close');
					           	  
				             };
				             
				             fwindow.callback=curWin.openerWin.setCv;
				             
		      	   	}
		      	});
		      	selectCvWin.openerWin=window;  
        }
        function setCv(cv){

                optWin.doForm.find('input[name="cvId"]').attr("value",cv.id);                          
                optWin.doForm.find('input[name="cvName"]').attr("value",cv.name);
                
                
        }
        function save(){          	   
        	  if (!$('#fm').form('validate')) return; 
            $('#fm').form('submit',{  
                url: url,  
                onSubmit: function(){  
                    return $(this).form('validate');  
                },  
                success: function(result){  
                    var result = eval('('+result+')');                      
                    if (result.success == true){  
                        $.messager.alert('信息',result.msg,'info');  
                        $('#dlg').dialog('close');      // close the dialog  
                        $('#dg').datagrid('reload');    // reload the user data  
                    } else {  
                        $.messager.alert('错误',result.msg,'error');
                    }  
                }  
            });  
        }  
        function deletes(){  
            var row = $('#dg').datagrid('getSelected');  
            
            var rows = $('#dg').datagrid('getSelections');  

            if (!rows||rows.length==0){
            	 $.messager.alert('提示','请选择要删除的行','info');
            	 return;
            }
            if (rows){  
                $.messager.confirm('重要提示','确定要删除?',function(r){  
                    if (r){  
                        $.post('/customer/customerContacter/delete.do',{ids:getRecordArray(rows,'id').join(',')},function(result){  
                            if (result.success){  
                                $('#dg').datagrid('reload');    // reload the user data  
                            } else {  
                                 
                                $.messager.alert('错误',result.errorMsg,'error'); 
                            }  
                        },'json');  
                    }  
                });  
            }  
        }  
        function reload(){        	
        	  $('#dg').datagrid('reload');
        }
        function find(){  
              
                //$('#dlg_query').dialog('open').dialog('setTitle','查询');  
                
                //url = '/customer/customerContacter/list.do';  
                 queryWin.window('open');   
                 queryWin.openWin=window; 
              
        } 
        	
        function query(formdata){  
                
                $('#dg').datagrid({
	                  queryParams: array2json(formdata)
                });
              
        }
        
        //生成grid的字段,需要字典的自动转换
        $('#dg').datagrid({
        	   columns:[[
        	   	
        	   	   {field:'cvName',title:'联系人姓名', width:100}
        	   	   ,{field:'role',title:'联系人角色', width:100,
        	   	   	 formatter: function(value,row,index){
        	   		      	return __getConstantCategoryCodeValue('CUSTOMER_CONTACTER', value);
        	   		      }        	   	   
        	   	   	}        	   	   
        	   	   
        	   	   ,{field:'creator',title:'创建人', width:100}
        	   	   ,{field:'createDt',title:'创建时间', width:100}
        	   	   ,{field:'modifier',title:'修改人', width:100}
        	   	   ,{field:'modifiedDt',title:'修改时间', width:100}
        	   	
        	   	
        	   ]]
        	   ,onDblClickRow: function(rowIndex, rowData){
        	    	//$('#dlg').dialog('open').dialog('setTitle','修改客户联系人');                  
                //$('#fm').form('load','/customer/customerContacter/get.do?id='+rowData.id);  
                //url = '/customer/customerContacter/update.do';        	    	
                doEdit(rowData.id);
        	    }
        }); 
        //完成-生成grid的字段
        
        
        
    </script>  
     
     

     
     
     
</body>  
</html>